/*     */ package net.gxf.nehe.learn;
/*     */ 
/*     */ import java.io.IOException;
/*     */ import java.nio.ByteBuffer;
/*     */ import java.nio.ByteOrder;
/*     */ import java.nio.IntBuffer;
/*     */ import org.lwjgl.input.Keyboard;
/*     */ import org.lwjgl.opengl.Display;
/*     */ import org.lwjgl.opengl.DisplayMode;
/*     */ import org.lwjgl.opengl.GL11;
/*     */ import org.lwjgl.util.glu.GLU;
/*     */ import org.newdawn.slick.opengl.Texture;
/*     */ import org.newdawn.slick.opengl.TextureLoader;
/*     */ import org.newdawn.slick.util.ResourceLoader;
/*     */ 
/*     */ public class TextureMapping
/*     */ {
/*  42 */   private boolean done = false;
/*  43 */   private boolean fullscreen = false;
/*  44 */   private final String windowTitle = "NeHe's OpenGL Lesson 6 for LWJGL (Texture Mapping)";
/*  45 */   private boolean f1 = false;
/*     */   private DisplayMode displayMode;
/*     */   private float xrot;
/*     */   private float yrot;
/*     */   private float zrot;
/*     */   private Texture texture;
/*     */ 
/*     */   public void run(boolean fullscreen)
/*     */   {
/*  55 */     this.fullscreen = fullscreen;
/*     */     try {
/*  57 */       init();
/*  58 */       while (!this.done) {
/*  59 */         mainloop();
/*  60 */         render();
/*  61 */         Display.update();
/*     */       }
/*  63 */       cleanup();
/*     */     } catch (Exception e) {
/*  65 */       e.printStackTrace();
/*  66 */       System.exit(0);
/*     */     }
/*     */   }
/*     */ 
/*     */   private void mainloop() {
/*  71 */     if (Keyboard.isKeyDown(1)) {
/*  72 */       this.done = true;
/*     */     }
/*  74 */     if (Display.isCloseRequested()) {
/*  75 */       this.done = true;
/*     */     }
/*  77 */     if ((Keyboard.isKeyDown(59)) && (!this.f1)) {
/*  78 */       this.f1 = true;
/*  79 */       switchMode();
/*     */     }
/*  81 */     if (!Keyboard.isKeyDown(59))
/*  82 */       this.f1 = false;
/*     */   }
/*     */ 
/*     */   private void switchMode()
/*     */   {
/*  87 */     this.fullscreen = (!this.fullscreen);
/*     */     try {
/*  89 */       Display.setFullscreen(this.fullscreen);
/*     */     } catch (Exception e) {
/*  91 */       e.printStackTrace();
/*     */     }
/*     */   }
/*     */ 
/*     */   private boolean render() {
/*  96 */     GL11.glClear(16640);
/*     */ 
/*  98 */     GL11.glLoadIdentity();
/*     */ 
/* 100 */     GL11.glTranslatef(0.0F, 0.0F, -5.0F);
/* 101 */     GL11.glRotatef(this.xrot, 1.0F, 0.0F, 0.0F);
/* 102 */     GL11.glRotatef(this.yrot, 0.0F, 1.0F, 0.0F);
/* 103 */     GL11.glRotatef(this.zrot, 0.0F, 0.0F, 1.0F);
/* 104 */     GL11.glBindTexture(3553, this.texture.getTextureID());
/* 105 */     GL11.glBegin(7);
/*     */ 
/* 107 */     GL11.glTexCoord2f(0.0F, 0.0F);
/* 108 */     GL11.glVertex3f(-1.0F, -1.0F, 1.0F);
/* 109 */     GL11.glTexCoord2f(1.0F, 0.0F);
/* 110 */     GL11.glVertex3f(1.0F, -1.0F, 1.0F);
/* 111 */     GL11.glTexCoord2f(1.0F, 1.0F);
/* 112 */     GL11.glVertex3f(1.0F, 1.0F, 1.0F);
/* 113 */     GL11.glTexCoord2f(0.0F, 1.0F);
/* 114 */     GL11.glVertex3f(-1.0F, 1.0F, 1.0F);
/*     */ 
/* 116 */     GL11.glTexCoord2f(1.0F, 0.0F);
/* 117 */     GL11.glVertex3f(-1.0F, -1.0F, -1.0F);
/* 118 */     GL11.glTexCoord2f(1.0F, 1.0F);
/* 119 */     GL11.glVertex3f(-1.0F, 1.0F, -1.0F);
/* 120 */     GL11.glTexCoord2f(0.0F, 1.0F);
/* 121 */     GL11.glVertex3f(1.0F, 1.0F, -1.0F);
/* 122 */     GL11.glTexCoord2f(0.0F, 0.0F);
/* 123 */     GL11.glVertex3f(1.0F, -1.0F, -1.0F);
/*     */ 
/* 125 */     GL11.glTexCoord2f(0.0F, 1.0F);
/* 126 */     GL11.glVertex3f(-1.0F, 1.0F, -1.0F);
/* 127 */     GL11.glTexCoord2f(0.0F, 0.0F);
/* 128 */     GL11.glVertex3f(-1.0F, 1.0F, 1.0F);
/* 129 */     GL11.glTexCoord2f(1.0F, 0.0F);
/* 130 */     GL11.glVertex3f(1.0F, 1.0F, 1.0F);
/* 131 */     GL11.glTexCoord2f(1.0F, 1.0F);
/* 132 */     GL11.glVertex3f(1.0F, 1.0F, -1.0F);
/*     */ 
/* 134 */     GL11.glTexCoord2f(1.0F, 1.0F);
/* 135 */     GL11.glVertex3f(-1.0F, -1.0F, -1.0F);
/* 136 */     GL11.glTexCoord2f(0.0F, 1.0F);
/* 137 */     GL11.glVertex3f(1.0F, -1.0F, -1.0F);
/* 138 */     GL11.glTexCoord2f(0.0F, 0.0F);
/* 139 */     GL11.glVertex3f(1.0F, -1.0F, 1.0F);
/* 140 */     GL11.glTexCoord2f(1.0F, 0.0F);
/* 141 */     GL11.glVertex3f(-1.0F, -1.0F, 1.0F);
/*     */ 
/* 143 */     GL11.glTexCoord2f(1.0F, 0.0F);
/* 144 */     GL11.glVertex3f(1.0F, -1.0F, -1.0F);
/* 145 */     GL11.glTexCoord2f(1.0F, 1.0F);
/* 146 */     GL11.glVertex3f(1.0F, 1.0F, -1.0F);
/* 147 */     GL11.glTexCoord2f(0.0F, 1.0F);
/* 148 */     GL11.glVertex3f(1.0F, 1.0F, 1.0F);
/* 149 */     GL11.glTexCoord2f(0.0F, 0.0F);
/* 150 */     GL11.glVertex3f(1.0F, -1.0F, 1.0F);
/*     */ 
/* 152 */     GL11.glTexCoord2f(0.0F, 0.0F);
/* 153 */     GL11.glVertex3f(-1.0F, -1.0F, -1.0F);
/* 154 */     GL11.glTexCoord2f(1.0F, 0.0F);
/* 155 */     GL11.glVertex3f(-1.0F, -1.0F, 1.0F);
/* 156 */     GL11.glTexCoord2f(1.0F, 1.0F);
/* 157 */     GL11.glVertex3f(-1.0F, 1.0F, 1.0F);
/* 158 */     GL11.glTexCoord2f(0.0F, 1.0F);
/* 159 */     GL11.glVertex3f(-1.0F, 1.0F, -1.0F);
/* 160 */     GL11.glEnd();
/*     */ 
/* 162 */     this.xrot += 0.3F;
/* 163 */     this.yrot += 0.2F;
/* 164 */     this.zrot += 0.4F;
/*     */ 
/* 166 */     return true;
/*     */   }
/*     */ 
/*     */   private void createWindow() throws Exception {
/* 170 */     Display.setFullscreen(this.fullscreen);
/* 171 */     DisplayMode[] d = Display.getAvailableDisplayModes();
/* 172 */     for (int i = 0; i < d.length; i++) {
/* 173 */       if ((d[i].getWidth() == 640) && (d[i].getHeight() == 480) && (d[i].getBitsPerPixel() == 32))
/*     */       {
/* 176 */         this.displayMode = d[i];
/* 177 */         break;
/*     */       }
/*     */     }
/* 180 */     Display.setDisplayMode(this.displayMode);
/* 181 */     Display.setTitle("NeHe's OpenGL Lesson 6 for LWJGL (Texture Mapping)");
/* 182 */     Display.create();
/*     */   }
/*     */ 
/*     */   private void init() throws Exception {
/* 186 */     createWindow();
/*     */ 
/* 189 */     loadTextures();
/* 190 */     initGL();
/*     */   }
/*     */ 
/*     */   private void loadTextures() throws IOException {
/* 194 */     this.texture = loadTexture("Data/NeHe.bmp");
/*     */   }
/*     */ 
/*     */   private void initGL() {
/* 198 */     GL11.glEnable(3553);
/* 199 */     GL11.glShadeModel(7425);
/* 200 */     GL11.glClearColor(0.0F, 0.0F, 0.0F, 0.0F);
/* 201 */     GL11.glClearDepth(1.0D);
/* 202 */     GL11.glEnable(2929);
/* 203 */     GL11.glDepthFunc(515);
/*     */ 
/* 205 */     GL11.glMatrixMode(5889);
/* 206 */     GL11.glLoadIdentity();
/*     */ 
/* 209 */     GLU.gluPerspective(45.0F, this.displayMode.getWidth() / this.displayMode.getHeight(), 0.1F, 100.0F);
/* 210 */     GL11.glMatrixMode(5888);
/*     */ 
/* 213 */     GL11.glHint(3152, 4354);
/*     */   }
/*     */ 
/*     */   private void cleanup() {
/* 217 */     Display.destroy();
/*     */   }
/*     */ 
/*     */   private Texture loadTexture(String path)
/*     */     throws IOException
/*     */   {
/* 225 */     this.texture = TextureLoader.getTexture("BMP", ResourceLoader.getResourceAsStream(path));
/* 226 */     IntBuffer image = ByteBuffer.allocateDirect(4).order(ByteOrder.nativeOrder()).asIntBuffer();
/*     */ 
/* 231 */     ByteBuffer scratch = ByteBuffer.allocateDirect(this.texture.getImageHeight() * this.texture.getImageWidth() * 3);
/*     */ 
/* 235 */     IntBuffer buf = ByteBuffer.allocateDirect(4).order(ByteOrder.nativeOrder()).asIntBuffer();
/* 236 */     GL11.glGenTextures(buf);
/*     */ 
/* 238 */     GL11.glBindTexture(3553, buf.get());
/*     */ 
/* 242 */     GL11.glTexParameteri(3553, 10241, 9729);
/*     */ 
/* 244 */     GL11.glTexParameteri(3553, 10240, 9729);
/*     */ 
/* 246 */     GL11.glTexImage2D(3553, 0, 6407, this.texture.getImageWidth(), this.texture.getImageHeight(), 0, 6407, 5121, scratch);
/*     */ 
/* 249 */     return this.texture;
/*     */   }
/*     */ 
/*     */   public static void main(String[] args) {
/* 253 */     boolean fullscreen = false;
/* 254 */     if ((args.length > 0) && 
/* 255 */       (args[0].equalsIgnoreCase("fullscreen"))) {
/* 256 */       fullscreen = true;
/*     */     }
/*     */ 
/* 260 */     TextureMapping l6 = new TextureMapping();
/* 261 */     l6.run(fullscreen);
/*     */   }
/*     */ }

/* Location:           C:\DBDownload\lwjglDemo2\lwjglDemo2\Run.jar
 * Qualified Name:     com.nehe.learn.TextureMapping
 * JD-Core Version:    0.6.2
 */